<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  PaymentRefund.php 2018-05-24 18:16 cunx $
   
*/
namespace common\library\wechat\payment;

use common\component\wechat\Wechat;
use common\library\wechat\WechatApi;

/**
 * 微信退款
 * Class PaymentRefund
 * @package common\library\wechat\payment
 */
class PaymentRefund extends WechatApi
{
    public static $apiType = 'payment';
    static $paymentId = 0;
    /**
     * 通过商户单号退款
     * @param string $outTradeNo    商户订单号
     * @param string $refundNumber  商户退款单号
     * @param int $totalFee         订单总金额（单位：分）
     * @param int $refundFee        本次退款金额（单位：分）
     * @param array $config         其他在微信参数列表中接受的参数
     * @return mixed
     * @author cunx
     */
    public static function byOutTradeNumber(string $outTradeNo, string $refundNumber, int $totalFee, int $refundFee, array $config = []){
        try {
            $result = self::getInstance()->refund->byOutTradeNumber($outTradeNo,$refundNumber,$totalFee,$refundFee,$config);
        }catch(\Exception $exception){
            $result = $exception;
        }
        return Wechat::apiError($result);
    }

    /**
     * 通过微信支付订单号退款
     * @param string $transactionId 微信支付订单号
     * @param string $refundNumber  商户退款单号
     * @param int $totalFee         订单总金额（单位：分）
     * @param int $refundFee        本次退款金额（单位：分）
     * @param array $config         其他在微信参数列表中接受的参数
     * @return mixed
     * @author cunx
     */
    public static function byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $config = []){
        try{
            $result = self::getInstance()->refund->byTransactionId($transactionId,$refundNumber,$totalFee,$refundFee,$config);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }

    /**
     * 微信支付订单号查询退款结果
     * @param $transactionId    微信支付订单号
     * @return mixed
     * @author cunx
     */
    static function queryByTransactionId($transactionId){
        try{
            $result = self::getInstance()->refund->byTransactionId($transactionId);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }

    /**
     * 商户订单号查询退款结果
     * @param $outTradeNumber   商户订单号
     * @return mixed
     * @author cunx
     */
    static function queryByOutTradeNumber($outTradeNumber){
        try{
            $result = self::getInstance()->refund->queryByOutTradeNumber($outTradeNumber);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }

    /**
     * 商户退款单号查询退款结果
     * @param $outRefundNumber  商户退款单号
     * @return mixed
     * @author cunx
     */
    static function queryByOutRefundNumber($outRefundNumber){
        try{
            $result = self::getInstance()->refund->queryByOutRefundNumber($outRefundNumber);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }

    /**
     * 微信退款单号查询退款结果
     * @param $refundId 微信退款单号
     * @return mixed
     * @author cunx
     */
    static function queryByRefundId(string $refundId){
        try{
            $result = self::getInstance()->refund->queryByRefundId($refundId);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }

}